package vn.com.demand.lux.view.labelprovider;

import vn.com.demand.lux.criteria.UpdateIssuingExpenseCriteria;
import vn.com.demand.lux.model.UpdateIssuingExpenseBean;
import vn.com.demand.lux.view.UpdateIssuingExpense;
import vn.com.demand.util.DpUtils;

/**
 * 
 * @author Huynh Tan Tai <httcntt@yahoo.com>
 *
 */
public class UpdateIssuingExpenseLabelProvider extends BasicLabelProvider {
	
	public String getColumnText(Object element, int columnIndex) {
		UpdateIssuingExpenseBean bean = (UpdateIssuingExpenseBean)element;
		UpdateIssuingExpenseCriteria criteria = UpdateIssuingExpense.getIssuingExpenseCriteria();
		String changedLedgerCode = criteria.getChangedLedgerCode();
		String desChangedLedgerCode = "";
		for (int i = 0; i < 9 - changedLedgerCode.length(); i++) {
			desChangedLedgerCode += " ";
		}
		criteria.setChangedLedgerCode(desChangedLedgerCode + changedLedgerCode);
		String format = "###,###,###,###.00";
		double value = 0;
		switch (columnIndex) {
		case 0:
			return DpUtils.trim(bean.getContractNumber());
		case 1:
			return DpUtils.trim(bean.getLedgerCode());
		case 2:
			return DpUtils.trim(bean.getLedgerName());
		case 3:
			return DpUtils.trim(bean.getJournalCode());
		case 4:
			return DpUtils.trim(bean.getEntryNumber());
		case 5:
			return DpUtils.trim(bean.getOurReference());
		case 6:
			value = bean.getAmount();
			return value != 0 ? DpUtils.format(value, format) : "";
		case 7:
			String query1 = "update gbkmut set reknr = 'ChangedLedgerCode' where ltrim(rtrim(dagbknr)) = 'JournalCode' and ltrim(rtrim(bkstnr)) = 'EntryNumber' and ltrim(rtrim(faktuurnr)) = 'OurReference' and ltrim(rtrim(reknr)) = 'OriginalLedgerCode'";
			query1 = query1.replaceAll("ChangedLedgerCode", criteria.getChangedLedgerCode());
			query1 = query1.replaceAll("JournalCode", DpUtils.trim(bean.getJournalCode()));
			query1 = query1.replaceAll("EntryNumber", DpUtils.trim(bean.getEntryNumber()));
			query1 = query1.replaceAll("OurReference", DpUtils.trim(bean.getOurReference()));
			query1 = query1.replaceAll("OriginalLedgerCode", DpUtils.trim(criteria.getOriginalLedgerCode()));
			return query1;
		case 8:
			String query2 = "update amutas set reknr = 'ChangedLedgerCode' where ltrim(rtrim(dagbknr)) = 'JournalCode' and ltrim(rtrim(bkstnr)) = 'EntryNumber' and ltrim(rtrim(faktuurnr)) = 'OurReference' and ltrim(rtrim(reknr)) = 'OriginalLedgerCode'";
			query2 = query2.replaceAll("ChangedLedgerCode", criteria.getChangedLedgerCode());
			query2 = query2.replaceAll("JournalCode", DpUtils.trim(bean.getJournalCode()));
			query2 = query2.replaceAll("EntryNumber", DpUtils.trim(bean.getEntryNumber()));
			query2 = query2.replaceAll("OurReference", DpUtils.trim(bean.getOurReference()));
			query2 = query2.replaceAll("OriginalLedgerCode", DpUtils.trim(criteria.getOriginalLedgerCode()));
			return query2;
		default:
			break;
		}
		return "";
	}
}
